<template>
  <div class="conical-chart">
    <div class="chart-title">{{ title }}</div>
    <div class="conical-container">
      <div class="conical-bars">
        <div 
          v-for="(item, index) in data" 
          :key="index"
          class="conical-item"
        >
          <div class="conical-bar-wrapper">
            <div 
              class="conical-bar"
              :style="{ 
                height: item.percentage + '%',
                background: `linear-gradient(to top, ${item.color}, ${item.color}80)`,
                boxShadow: `0 0 15px ${item.color}`
              }"
            ></div>
          </div>
          <div class="conical-label">{{ item.name }}</div>
          <div class="conical-value">{{ item.value }}</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'ConicalChart',
  props: {
    title: {
      type: String,
      default: '锥形柱图'
    },
    data: {
      type: Array,
      default: () => [
        { name: '产品A', value: 85, percentage: 85, color: '#00d4ff' },
        { name: '产品B', value: 72, percentage: 72, color: '#00ff88' },
        { name: '产品C', value: 68, percentage: 68, color: '#ff6b6b' },
        { name: '产品D', value: 45, percentage: 45, color: '#ffd93d' },
        { name: '产品E', value: 38, percentage: 38, color: '#6c5ce7' }
      ]
    }
  },
  mounted() {
    this.animateBars()
  },
  methods: {
    animateBars() {
      const bars = this.$el.querySelectorAll('.conical-bar')
      bars.forEach((bar, index) => {
        setTimeout(() => {
          bar.style.transform = 'scaleY(1)'
        }, index * 200)
      })
    }
  }
}
</script>

<style scoped>
.conical-chart {
  width: 100%;
  height: 100%;
  padding: 20px;
  box-sizing: border-box;
}

.chart-title {
  color: #fff;
  font-size: 16px;
  font-weight: bold;
  margin-bottom: 20px;
  text-align: center;
}

.conical-container {
  height: calc(100% - 60px);
  display: flex;
  align-items: end;
  justify-content: center;
}

.conical-bars {
  display: flex;
  align-items: end;
  gap: 15px;
  height: 100%;
}

.conical-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  flex: 1;
}

.conical-bar-wrapper {
  height: 150px;
  display: flex;
  align-items: end;
  justify-content: center;
  width: 100%;
}

.conical-bar {
  width: 20px;
  border-radius: 10px 10px 0 0;
  transform: scaleY(0);
  transform-origin: bottom;
  transition: transform 0.5s ease;
  position: relative;
}

.conical-bar::before {
  content: '';
  position: absolute;
  top: -5px;
  left: -2px;
  right: -2px;
  height: 10px;
  background: inherit;
  border-radius: 10px 10px 0 0;
  opacity: 0.3;
}

.conical-label {
  color: #fff;
  font-size: 10px;
  text-align: center;
  white-space: nowrap;
}

.conical-value {
  color: #00d4ff;
  font-size: 12px;
  font-weight: bold;
}
</style>